# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Simone Sclavi 'Ito' <darkhado@gmail.com>

pkgname=libjpeg-turbo
pkgver=3.0.1
pkgrel=1
pkgdesc="JPEG image codec with accelerated baseline compression and decompression"
url="https://libjpeg-turbo.org/"
arch=(loong64 x86_64)
license=(
  BSD-3-Clause
  IJG
  Zlib
)
depends=(glibc)
makedepends=(
  cmake
  ninja
  nasm
  'jdk11-openjdk'
)
optdepends=('java-runtime>11: for TurboJPEG Java wrapper')
provides=(
  libjpeg
  libjpeg.so
  libturbojpeg.so
)
source=(
  https://sourceforge.net/projects/$pkgname/files/$pkgver/$pkgname-$pkgver.tar.gz{,.sig}
)
sha512sums=('26a2c821a023579e82a7c2a00582747f5f24089aa0820ba304f1ff71c6894b7a6bd0468acc5ff90e2655e0a1c23a5a35a779df51f5cfa3e9eba527c709fab55b'
            'SKIP')
b2sums=('9d2c784edd6493c4d9e2379fc4a8f0844e440d7afe774b231f611034d481dcf1be35979fb7d731a5a8f99000780f1343b7934a59df22c1dcaef295b6294ea494'
        'SKIP')
validpgpkeys=('0338C8D8D9FDA62CF9C421BD7EC2DBB6F4DBF434') # The libjpeg-turbo Project (Signing key for official binaries) <information@libjpeg-turbo.org>

build() {
  local cmake_options=(
    -B build
    -D CMAKE_INSTALL_PREFIX=/usr
    -D CMAKE_INSTALL_LIBDIR=/usr/lib
    -D CMAKE_BUILD_TYPE=None
    -D ENABLE_STATIC=OFF
    -D WITH_JAVA=ON
    -D WITH_JPEG8=ON
    -D WITH_SIMD=OFF
    -G Ninja
    -S $pkgname-$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build -v
}

check() {
  ctest --test-dir build --output-on-failure --stop-on-failure -j$(nproc)
}

package() {
  DESTDIR="$pkgdir" cmake --install build -v

  # header required by some dependents
  # https://bugs.archlinux.org/task/24787
  install -vDm 644 $pkgname-$pkgver/jpegint.h "$pkgdir/usr/include"

  install -vDm 644 $pkgname-$pkgver/LICENSE.md -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/README.ijg -t "$pkgdir/usr/share/licenses/$pkgname/"
}
